package com.example.demo99.Controller;

import com.example.demo99.Entity.AfterSaleRequest;
import com.example.demo99.Service.AfterSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/after-sale")
public class AfterSaleController {

    @Autowired
    private AfterSaleService afterSaleService;

    @PostMapping("/apply")
    public String apply(@RequestBody AfterSaleRequest request) {
        afterSaleService.createRequest(request);
        return "申请成功";
    }

    @PostMapping("/review/{id}")
    public String review(@PathVariable Long id, @RequestParam String action) {
        afterSaleService.reviewRequest(id, action);
        return "审核完成：" + action;
    }

    @PostMapping("/refund/{id}")
    public String refund(@PathVariable Long id) {
        afterSaleService.refund(id);
        return "退款完成";
    }

    @GetMapping("/all")
    public List<AfterSaleRequest> all() {
        return afterSaleService.findAll();
    }
}